import React, { Component } from 'react'
import { withRouter } from 'react-router-dom/cjs/react-router-dom.min'

class Title extends Component {
  // 回退回调
  back = () =>{
    this.props.history.goBack()
  }

  // 前进回调
  forword = () =>{
    this.props.history.goForward()
  }

  render() {
    return (
      <div>
        <h1>React Router Demo</h1>
        <button onClick={this.forword}>前进</button>
        <button onClick={this.back}>回退</button>
      </div>
    )
  }
}

export default withRouter(Title)

//withRouter可以加工一般组件，让一般组件具备路由组件所特有的API
//withRouter的返回值是一个新组件